package jk.framework.spring.cloud.canary.loadbalancer.comonpent;

import jk.framework.canary.core.po.RouteContext;
import jk.framework.spring.cloud.canary.loadbalancer.context.CanaryLoadBalanceRouteContext;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.Request;
import org.springframework.cloud.client.loadbalancer.RequestData;
import org.springframework.cloud.client.loadbalancer.RequestDataContext;

/**
 * @author cuichao
 */
public class DefaultLoadBalanceRouteContextFactory implements LoadBalanceRouteContextFactory{

    @Override
    public RouteContext<RequestData> getContext(ServiceInstance instance, Request request) {
        RequestData clientRequest = ((RequestDataContext) request.getContext()).getClientRequest();
        return  CanaryLoadBalanceRouteContext.build(instance, clientRequest);
    }


}
